﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Wild2.Models.Pages.Topic.Index>" %>
<asp:Content ID="TitleContent" ContentPlaceHolderID="TitleContent" runat="server">
    <%= Resources.Home.Title %>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderContent" runat="server">
    <%  String version = "pda"; if (Session[Wild2.Models.Constants.SessionConstants.VERSION] != null) version = Session[Wild2.Models.Constants.SessionConstants.VERSION].ToString(); %>
    <% Html.RenderPartial("~/Views/Shared/" + version + "/Header.ascx", "Тема из дневника"); %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%  String version = "pda"; if (Session[Wild2.Models.Constants.SessionConstants.VERSION] != null) version = Session[Wild2.Models.Constants.SessionConstants.VERSION].ToString(); %>
    <% if (!String.IsNullOrEmpty(Model.infoMessage))
       {
           Html.RenderPartial("~/Views/Shared/" + version + "/InfoBox.ascx", Model.infoMessage);
       } %>
       <div class="container">
    <% 
        if (Model.Topic != null)
        {
            Html.RenderPartial("~/Views/Shared/" + version + "/Panel.ascx", HttpUtility.HtmlEncode(Model.Topic.Caption));
            Html.RenderPartial("~/Views/Shared/" + version + "/Element.ascx", Wild2.Models.Text.Helper.smiles(Wild2.Models.Text.Helper.Bbcode(Wild2.Models.Text.Helper.nbsp(Server.HtmlEncode(Model.Topic.Text)), true), 5, 1));
            if (!String.IsNullOrEmpty(Model.Topic.TextLarge)) Html.RenderPartial("~/Views/Shared/" + version + "/Element.ascx", Wild2.Models.Text.Helper.smiles(Wild2.Models.Text.Helper.Bbcode(Wild2.Models.Text.Helper.nbsp(Server.HtmlEncode(Model.Topic.TextLarge)), true), 5, 1));
            String tags = "";
            int length = Model.Topic.Tags.Count;
            for (int i = 0; i < length; i++)
            {
                tags += "<a href=\"" + Url.Action("Tags", "Blog", new { tag = Model.Topic.Tags[i] }) + "\">" + HttpUtility.HtmlEncode(Model.Topic.Tags[i]) + "</a>";
                if (i < length - 1) tags += ", ";
                
            }
            if (!String.IsNullOrEmpty(tags))
            {
                Html.RenderPartial("~/Views/Shared/" + version + "/Element.ascx", "Теги: " + tags);
            }
            if (DateTime.Now.AddDays(-1).CompareTo(Model.Topic.Date) == -1) Html.RenderPartial("~/Views/Shared/" + version + "/Element.ascx", "Написал " + Html.ActionLink(HttpUtility.HtmlEncode(Model.Topic.UserNick), "Index", "User", new { id = Model.Topic.UserID }, null) + " " + Wild2.Models.Text.Helper.GetDateDiff(Model.Topic.Date));
            else Html.RenderPartial("~/Views/Shared/" + version + "/Element.ascx", "Написал " + Html.ActionLink(HttpUtility.HtmlEncode(Model.Topic.UserNick), "Index", "User", new { id = Model.Topic.UserID }, null) + " " + Model.Topic.Date.ToString());
            Html.RenderPartial("~/Views/Shared/" + version + "/Element.ascx", Html.ActionLink("-", "Vote", new { topic = Model.Topic.ID, vote = -1, hash = Wild2.Models.Auth.AuthOnSite.GetSessionHash() }, new { @class = "vote_button" }) + " <b>" + Html.ActionLink(Model.Topic.Rating.ToString(), "Index", new { id = Model.Topic.ID, votes = "full" }, new { }) + "</b> " + Html.ActionLink("+", "Vote", new { topic = Model.Topic.ID, vote = 1, hash = Wild2.Models.Auth.AuthOnSite.GetSessionHash() }, new { @class = "vote_button" }));
            if (Model.Votes != null)
            {
                %>
                Проголосовали за:
                <%
                foreach (var vote in Model.Votes)
                {
                    if (vote.Vote > 0)
                    {
                        %>
                            <%= HttpUtility.HtmlEncode(vote.UserNick) %>
                        <%
                    }
                }   
                %>
                <br />Проголосовали против:
                <%
                foreach (var vote in Model.Votes)
                {
                    if (vote.Vote < 0)
                    {
                        %>
                            <%= HttpUtility.HtmlEncode(vote.UserNick)%>
                        <%
                    }
                }  
            }
            Html.RenderPartial("~/Views/Shared/" + version + "/Panel.ascx", "Комментарии:");
            %>
            <% 
            Int32? UserID = Model.UserID;
            int id = Convert.ToInt32(Url.RequestContext.RouteData.Values["id"]);
               foreach (var comment in Model.Comments)
               {
                   int level = comment.Level.Split(new char[] { '-' }).Length - 1;
                   %>
                    <div id="<%= comment.ID %>" name="<%= comment.ID %>" class="elb" style="padding: 0.4em; margin-left: <%= level %>em; margin-bottom: 0px;">
                        <%= Html.ActionLink(HttpUtility.HtmlEncode(comment.Nick), "Index", "Topic", null, null, comment.ID.ToString(), new { id = (comment.ID * -1) }, new { @class = ((comment.LastOnlineDate.AddMinutes(15).CompareTo(DateTime.Now) == 1) ? ("online") : ("offline")) })%> 
                        <%= ((DateTime.Now.AddDays(-1).CompareTo(Model.Topic.Date) == -1) ? Wild2.Models.Text.Helper.GetDateDiff(comment.Date) : comment.Date.ToString()) %>
                        <br />
                        <%= Wild2.Models.Text.Helper.smiles(Wild2.Models.Text.Helper.Bbcode(Wild2.Models.Text.Helper.nbsp(Server.HtmlEncode(comment.Text)), true), 5, 1) %>
                    </div>
                    <%
                       if ((UserID.HasValue) && (id < 0) && (comment.ID == id * -1))
                       {
                           Html.RenderPartial("~/Views/Shared/" + version + "/Input.ascx", new System.Collections.Generic.KeyValuePair<Int32, String>(level, ""));
                       }
                     %>
            <% } %>
            <%
            if (UserID.HasValue)
            {
                Html.RenderPartial("~/Views/Shared/" + version + "/Input2.ascx", new System.Collections.Generic.KeyValuePair<Int32, String>(0, ""));
            }
        }
        else
        {
            Html.RenderPartial("~/Views/Shared/" + version + "/Element.ascx", "Тема не найдена");
        }
    %>
        </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="FooterContent" runat="server">
    <%  String version = "pda"; if (Session[Wild2.Models.Constants.SessionConstants.VERSION] != null) version = Session[Wild2.Models.Constants.SessionConstants.VERSION].ToString(); %>
    <% //Html.RenderPartial("~/Views/Shared/" + version + "/Footer.ascx", "", new ViewDataDictionary() { { "showlegend", true } });
        Html.RenderPartial("~/Views/Shared/" + version + "/Footer.ascx");
        %>
        <%--<script type="text/javascript" language="javascript">window.location.hash=5</script>--%>
</asp:Content>
